#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n],dp[n+1] = {
		100001
	},l = 1;
	for(int i = 0;i < n;++i){
		cin>>a[i];
	}
	dp[l] = a[0];
	for(int i = 1;i < n;++i){
		if(dp[l]>=a[i])
			dp[++l] = a[i];
		else{
			int j = upper_bound(dp,dp+l,a[i], greater<int>())-dp;
			dp[j] = a[i];
		}
	}
	cout<<l;
	return 0;
	
}
